var tempChargeList = function(targetObj){
    this.sysUtils = new kendoUtils();
    this.targetObj = targetObj;
    this.init();
    return this;
};
tempChargeList.prototype={
    init:function(){
        var bindFieldArray = this.sysUtils.getBindFieldArray(this.targetObj.find(".search-panel"));
        var bindFunctionArray = [{fName:"queryInfo",fs:this.findGridData},{fName:"resetInfo",fs:this.resetInfo}];
        this.bindBaseModels = new bindBaseModel(null,bindFieldArray,bindFunctionArray,null);
        this.sysUtils.bindDoucment(this.bindBaseModels,this.targetObj,this);
        this.findGridData();
    },
    /*
     * 重置按钮
     */
    resetInfo:function(e){
        var that = $(e.target).data("that");
        that.sysUtils.setBindFieldNull(that.bindBaseModels.bindFieldArray);
        that.findGridData();
    },
    findGridData:function (e) {
        var that = this;
        if(isNotEmpt(e)){
            that = $(e.target).data("that");
        }
        var jsonObj = that.sysUtils.getBindDocJson();
        jsonObj["chargeType"] = 1;
        var dataT = {curdatetime:new Date().getTime(),json:JSON.stringify(jsonObj)};
        var source = that.sysUtils.getDataSource({url : baseApiPath + 'chargeStandard/chargeList', data : dataT, dataType : 'odata'});
        /*  JsonpAjax(url, dataT, "odata", function(res) {

         })
         console.info(source);*/
        that.targetObj.find("#pager").kendoPager({
            dataSource: source
        });
        that.targetObj.find("#listView").kendoListView({
            dataSource: source,
            // selectable: "multiple",
            template: kendo.template(that.targetObj.find("#template").html())
        });
    },

    openChargeWindow:function (chargeCode,isEdit) {
        var that = this;
        var titles = "";
        that.editResult = null;
        that.isEdit = null;
        var openwidonw = function(){
            that.monthChargeDivId = that.sysUtils.openWindow(that.monthChargeDivId,{
                title:titles,
                height:"630px",
                width:"980px",
                resizable:true,
                content:"views/parkLotCenter/chargeStandard/tempChargeTab.html"
            }, true);
        };
        var ajaxPost = function(){
            JsonpAjax(baseApiPath+"chargeStandard/queryChargeInfo?chargeCode=" + chargeCode,null,"json",function(result){
                that.editResult = result;
                openwidonw();
            });
        };
        if(undefined == chargeCode && null == isEdit){  //表示新增界面
            titles = "新增收费标准";
            that.isEdit = false;
            openwidonw();
        }else if(true == isEdit){  //编辑界面
            //获取选中行的用户编号
            var id = that.getSelectOptions();
            if(id == ''){
                notification({ title:"操作失败",message:"请选择至少一条需要修改的记录!!"},'info');
                return;
            }else{
                var ids = id.split(',');
                if(ids.length>1){
                    notification({ title:"操作失败",message:"请选择一条需要修改的记录!!"},'info');
                    return;
                }
            }
            chargeCode = id;
            titles = "编辑收费标准信息";
            that.isEdit = true;
            ajaxPost();
        }else{    //查询界面
            titles = "查询收费标准信息";
            that.isEdit = false;
            ajaxPost();
        }
    },
    delete:function (e) {
        var that = this;
        if (!isEmpty(e)) {
            that = $(e.target).data("that");
        }
        var ids = this.getSelectOptions();
        if (ids == '') {
            notification({ title:"操作失败", message:"请选择至少一条需要删除的记录!!"},'info');
            return;
        }
        notification({title:"确认信息", message:"确定删除选中数据？"}, 'confirm', {
            callback : function(){
                $.ajax({
                    url : baseApiPath + "chargeStandard/delete",
                    type : "post",
                    data : {"ids" : ids},
                    dataType : "json",
                    success : function(res) {
                        if (res != "") {
                            notification({ title:"删除成功", message:"删除的数据有 : {"+ids+"}"},'info');
                            that.findGridData();
                        }
                    },
                    error : function() {
                        notification({ title:"删除失败", message:"请检查联网状态"}, 'info');
                    }
                });
            }
        });
    },
    getSelectOptions:function () {
        var that = this;
        var id = '';
        that.targetObj.find("#listView").find("input[type=checkbox]:checked").each(function(){
            id += this.value + ',';
        });
        if(id.indexOf(',')){
            id = id.substr(0,id.length-1);
        }
        return id;
    }
};

